﻿Imports Newtonsoft.Json

Public Class OvertimeManager

    Private manager As SQLManager


    Public Sub New()
        manager = New SQLManager
    End Sub

   
    Public Function computeTotalOvertimeHours(ByVal fromDate As DateTime, ByVal toDate As DateTime, ByVal emp As Employee) As Integer

        Dim contObject As New List(Of containerClass)
        Dim query As String = "SELECT SUM(ot_hours) as totalot FROM `tbl_overtime` WHERE employee_id='" + emp.id.ToString + "' AND `status`='1' AND (`ot_from` >= '" + fromDate.ToString("yyyy-M-d HH:mm:ss") + "' AND `ot_to` <='" + toDate.ToString("yyyy-M-d HH:mm:ss") + "')"


        Dim resultString As String = "" + manager.executeQuery(query)


        contObject = JsonConvert.DeserializeObject(Of List(Of containerClass))(resultString)
        If contObject.Count > 0 Then
            If Not contObject(0).totalot Is Nothing Then
                If IsNumeric(contObject(0).totalot) Then
                    Return contObject(0).totalot
                End If
            End If

        End If
        Return 0
    End Function

    Private Class containerClass
        Public totalot As String
    End Class

End Class
